package com.huadao.cart_ccs.modle;

import com.huadao.cart_ccs.base.BaseSerialPortModel;
import com.huadao.cart_ccs.common.ByteUtils;
import com.huadao.cart_ccs.data.bo.CommandWord;
import com.huadao.cart_ccs.data.bo.MagneticStirrerBO;
import com.huadao.cart_ccs.data.bo.Protocol;

/**
 * 磁力搅拌器
 */
public class MagneticStirrerModel extends BaseSerialPortModel {

    private String TAG="磁力搅拌器";

    public void openMagneticStirrer(int speed){
        byte[] speedByte= ByteUtils.int2bytesLG(2,speed);
        setMagneticStirrer(MagneticStirrerBO.star,speedByte, MagneticStirrerBO.directionForward);
    }

    public void closeMagneticStirrer(){
        setMagneticStirrer(MagneticStirrerBO.stop,null, (byte) 0);
    }

    private void setMagneticStirrer(byte order,byte[] speed,byte direction){
        byte[] orderContent;
        if(order== MagneticStirrerBO.star) {//启动
            orderContent = new byte[speed.length + 1];
            for (int i = 0; i < orderContent.length - 1; i++) {
                orderContent[i] = speed[i];
            }
            orderContent[2] = direction;
        }else {//停止
            orderContent = new byte[]{00};
        }
        Protocol params = ByteUtils.generateProtocol(CommandWord.write, new byte[]{MagneticStirrerBO.ModularType_MagneticStirrer, MagneticStirrerBO.magneticStirrer_NO1,order}, orderContent);
        serialPortRequest(params);
    }
}
